﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace Weazel.Gezel.Simulator.Reference
{
  class FinishDirective : IDirective
  {
    private readonly Symid id, sfg;

    /// <summary>
    /// The datapath which contains this $finish directive
    /// </summary>
    private readonly Datapath datapath;

    /// <summary>
    /// The simulation to which this
    /// finish directive belongs. Used
    /// to finish the simulation.
    /// </summary>
    private readonly Simulation simulation;

    public FinishDirective(Simulation sim, Symid id, Symid sfg, Datapath datapath)
    {
      this.simulation = sim;
      this.id = id;
      this.sfg = sfg;
      this.datapath = datapath;
    }
    public void AddString(string var)
    {
      throw new NotSupportedException();
    }

    public void AddVariable(AbstractSignal artsignal)
    {
      throw new NotSupportedException();
    }

    public bool CanExecute()
    {
      if (datapath.IsSignalFlowGraphActive(sfg))
        return true;
      return false;
    }

    public void Execute(long g, StringBuilder buffer)
    {
      buffer.AppendLine("finish reached !");
      simulation.Finish();
    }

    public void AddCycle()
    {
      throw new NotSupportedException();
    }
  }
}
